<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Mirrored from bos.asmhackers.net/docs/filesystems/fat12-16-32/docs/lecture.html by HTTrack Website Copier/3.x [XR&CO'2013], Tue, 07 Oct 2014 11:26:02 GMT -->
<head>
        <title>The FAT File System</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Expires" content="Wed, 31 Jan 2007 23:59:59 GMT">
    </head>
    <body>
    <p>
        CIS-24 Home
        <a href="http://www.c-jump.com/CIS24/CIS24syllabus.htm"><tt>http://www.c-jump.com/CIS24/CIS24syllabus.htm</tt></a>
    </p>
    <h3>
        The FAT File System
    </h3>
    <hr>
        <ol>
            <li><a href="#F01_0010_overview">FAT Overview</a></li>
            <li><a href="#F01_0020_fat">Boot Sector, FAT, Root Directory, and Files</a></li>
            <li><a href="#F01_0030_layout">FAT File System Layout</a></li>
            <li><a href="#F01_0040_clusters_n_sectors">FAT Clusters and Sectors</a></li>
            <li><a href="#F01_0050_unallocated">FAT, Slack, and Unallocated Space</a></li>
            <li><a href="#F01_0060_first_cluster">Where is the First FAT Cluster?</a></li>
            <li><a href="#F01_0070_boot_sector">Boot Sector</a></li>
            <li><a href="#F01_0080_boot_sector_bytes">FAT Boot Sector, bytes 0-35 (FAT12/16 and FAT32)</a></li>
            <li><a href="#F01_0090_boot_sector">FAT Boot Sector (FAT12/16)</a></li>
            <li><a href="#F01_0100_fat12_boot_sector">FAT12 Boot Sector</a></li>
            <li><a href="#F01_0110_interpretation">Boot Sector Interpretation</a></li>
            <li><a href="#F01_0120_capacity">Capacity of this Medium</a></li>
            <li><a href="#F01_0130_sector_assignments">Sector Assignments</a></li>
            <li><a href="#F01_0140_root_directory">Root Directory</a></li>
            <li><a href="#F01_0150_entries">Root Directory Entries</a></li>
            <li><a href="#F01_0160_sfn">Root Directory Entry Format (SFN)</a></li>
            <li><a href="#F01_0170_example">Root Directory Example</a></li>
            <li><a href="#F01_0180_sample">Sample Root Directory Entry</a></li>
            <li><a href="#F01_0190_another_sample">Another Sample Root Directory Entry</a></li>
            <li><a href="#F01_0200_fats_compared">FATs Compared</a></li>
            <li><a href="#F01_0210_fat12">FAT12 File Allocation Table</a></li>
            <li><a href="#F01_0220_interpreting">Interpreting FAT12</a></li>
            <li><a href="#F01_0230_fat12_contents">FAT12 Contents</a></li>
            <li><a href="#F01_0240_formatting">Formatting a Floppy</a></li>
            <li><a href="#F01_0250_formatted">Formatted Floppy Data Structures</a></li>
            <li><a href="#F01_0260_new_file">Allocating A New File</a></li>
            <li><a href="#F01_0270_deleting">Deleting A File</a></li>
            <li><a href="#F01_0280_information">For More Information...</a></li>
        </ol>
<a id="F01_0010_overview"></a>


    <h3>
        1. FAT Overview
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    Simple - and common - file system
   </p>
  </li>
  <li>
   <p>
    Found on all Windows OS and many devices
   </p>
   <ul>
    <li>
     <p>
      <strong>FAT12</strong>: Developed 1977 (MS Disk BASIC)
     </p>
    </li>
    <li>
     <p>
      <strong>FAT16</strong>: Developed 1987 (MS-DOS 3.31)
     </p>
    </li>
    <li>
     <p>
      <strong>FAT32</strong>: Developed 1996 (Win95 OSR2)
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Few data structures supported:
   </p>
   <ul>
    <li>
     <p>
      <span style="color: blue">Cluster</span>: Basic storage unit for files
     </p>
    </li>
    <li>
     <p>
      <span style="color: blue">Directory</span>: Lists file name, starting cluster, and length
     </p>
    </li>
    <li>
     <p>
      <span style="color: blue">File Allocation Table</span>: Contains cluster status and pointer to next cluster in chain
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0020_fat"></a>


    <h3>
        2. Boot Sector, FAT, Root Directory, and Files
    </h3>
 <hr>
     <table border="0" cellpadding="2" cellspacing="0">
         <tbody><tr>
             <td valign="top">
 <ul>
  <li>
   <p>
    File <tt>tyui.jpg</tt>:
   </p>
   <ul>
    <li>
     <p>
      occupies clusters 2, 3, and 4.
     </p>
    </li>
    <li>
     <p>
      The file size is 1,400 bytes, it occupies 1,536 bytes (3 clusters)
 on the disk, and cluster 4 includes 136 bytes of slack space.
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    File <tt>mes.doc</tt>:
   </p>
   <ul>
    <li>
     <p>
      occupies clusters 5 and 6.
     </p>
    </li>
    <li>
     <p>
      The file size is 980 bytes, it occupies 1,024 bytes (2 clusters), and has 44 bytes of slack space in cluster 6.
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Clusters 7, 8, and 9 are unallocated.
   </p>
  </li>
 </ul>
             </td>
             <td valign="top">
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/fat_root.png" alt="Boot Sector, FAT, Root Directory, and Files">
   </p>
  </li>
 </ul>
             </td>
         </tr>
     </tbody></table>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0030_layout"></a>


    <h3>
        3. FAT File System Layout
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/fat_layout.png" alt="FAT File System Layout">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0040_clusters_n_sectors"></a>


    <h3>
        4. FAT Clusters and Sectors
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    A cluster is a group of consecutive sectors
   </p>
   <ul>
    <li>
     <p>
      A sector is usually 512 B
     </p>
    </li>
    <li>
     <p>
      A cluster is 1, 2, 4, 8, 16, 32, or 64 sectors (i.e., it can range from 512 B to 32 KB)
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Each cluster has an address
   </p>
  </li>
  <li>
   <p>
    The first cluster has an address of 2
   </p>
   <ul>
    <li>
     <p>
      I.e., there is no addressable cluster 0 or 1
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0050_unallocated"></a>


    <h3>
        5. FAT, Slack, and Unallocated Space
    </h3>
 <hr>
     <table border="0" cellpadding="2" cellspacing="0">
         <tbody><tr>
             <td valign="top">
 <ul>
  <li>
   <p>
    Clusters 3, 6, and 8 are allocated; clusters 2, 4, 5, 7, and 9 are unallocated
   </p>
  </li>
  <li>
   <p>
    Clusters 6 and 8 are only partially filled; the unused portion is slack space
   </p>
  </li>
  <li>
   <p>
    File <tt>gary.txt</tt>:
   </p>
   <ul>
    <li>
     <p>
      logical size is 1,034 bytes
     </p>
    </li>
    <li>
     <p>
      physical size is 2,048 bytes (slack = 1,014 B)
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    File <tt>hello.jpg</tt>:
   </p>
   <ul>
    <li>
     <p>
      logical size is 3,973 bytes
     </p>
    </li>
    <li>
     <p>
      physical size is 4,096 bytes (slack = 123 B)
     </p>
    </li>
   </ul>
  </li>
 </ul>
             </td>
             <td valign="top">
 <ul style="list-style-type:none;">
  <img src="lecture-filer/unallocated_space.png" alt="FAT, Slack, and Unallocated Space">
 </ul>
             </td>
         </tr>
     </tbody></table>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0060_first_cluster"></a>


    <h3>
        6. Where is the First FAT Cluster?
    </h3>
 <hr>
     <table border="0" cellpadding="2" cellspacing="0">
         <tbody><tr>
             <td valign="top">
 <ul>
  <li>
   <p>
    The first cluster is Cluster 2
   </p>
  </li>
  <li>
   <p>
    Actual location of cluster 2 is different in FAT12/16 and FAT32
   </p>
  </li>
  <li>
   <p>
    Assume cluster size = 2,048 B (4 sectors)
   </p>
  </li>
  <li>
   <p>
    Assume that data area starts at sector 1224
   </p>
  </li>
  <li>
   <p>
    First sectors of data area are reserved for the Root Directory
   </p>
   <ul>
    <li>
     <p>
      Size is established at boot time
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Cluster 2 starts after Root Directory
   </p>
  </li>
  <li>
   <p>
    Root directory is set at 32 sectors
   </p>
   <ul>
    <li>
     <p>
      Occupies sectors 1,224-1,255
     </p>
    </li>
   </ul>
  </li>
 </ul>
             </td>
             <td valign="top">
 <ul style="list-style-type:none;">
  <li>
   <p>
     FAT12/16 Cluster Example:
   </p>
   <p>
    &nbsp;
    <img src="lecture-filer/fat12_16_cluster_example.png" alt="FAT12/16 Cluster Example">
   </p>
  </li>
 </ul>
 <ul>
  <li>
   <p>
    Cluster 2 starts at sector 1,256
   </p>
  </li>
  <li>
   <p>
    Cluster 3 starts at sector 1,260
   </p>
  </li>
  <li>
   <p>
    Cluster 4 at 1,264...
   </p>
  </li>
 </ul>
             </td>
         </tr>
     </tbody></table>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0070_boot_sector"></a>


    <h3>
        7. Boot Sector
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    First sector of a FAT system is the boot sector
   </p>
   <ul>
    <li>
     <p>
      Contains most of the information with which to determine
     </p>
     <ul>
      <li>
       <p>
        the file system type, and
       </p>
      </li>
      <li>
       <p>
        size and location of data structures
       </p>
      </li>
     </ul>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Boot sector format is different for FAT12/16 and FAT32
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0080_boot_sector_bytes"></a>


    <h3>
        8. FAT Boot Sector, bytes 0-35 (FAT12/16 and FAT32)
    </h3>
 <hr>
 <ul style="list-style-type:none;">
      <table border="1" cellpadding="5" cellspacing="0">
          <tbody><tr>
              <th>
                  Bytes
              </th>
              <th>
                  Purpose
              </th>
          </tr>
          <tr>
              <td align="left">
                  0-2
              </td>
              <td>
                  Assembly code instructions to jump to boot code (mandatory in bootable partition)
              </td>
          </tr>
          <tr>
              <td align="left">
                  3-10
              </td>
              <td>
                  OEM name in ASCII
              </td>
          </tr>
          <tr>
              <td align="left">
                  11-12
              </td>
              <td>
                  Bytes per sector (512, 1024, 2048, or 4096)
              </td>
          </tr>
          <tr>
              <td align="left">
                  13
              </td>
              <td>
                  Sectors per cluster (Must be a power of 2 and cluster size must be &lt;=32 KB)
              </td>
          </tr>
          <tr>
              <td align="left">
                  14-15
              </td>
              <td>
                  Size of reserved area, in sectors
              </td>
          </tr>
          <tr>
              <td align="left">
                  16
              </td>
              <td>
                  Number of FATs (usually 2)
              </td>
          </tr>
          <tr>
              <td align="left">
                  17-18
              </td>
              <td>
                  Maximum number of files in the root directory (FAT12/16; 0 for FAT32)
              </td>
          </tr>
          <tr>
              <td align="left">
                  19-20
              </td>
              <td>
                  Number of sectors in the file system; if 2 B is not large enough, set to 0 and use
                  4 B value in bytes 32-35 below
              </td>
          </tr>
          <tr>
              <td align="left">
                  21
              </td>
              <td>
                  Media type (0xf0=removable disk, 0xf8=fixed disk)
              </td>
          </tr>
          <tr>
              <td align="left">
                  22-23
              </td>
              <td>
                  Size of each FAT, in sectors, for FAT12/16; 0 for FAT32
              </td>
          </tr>
          <tr>
              <td align="left">
                  24-25
              </td>
              <td>
                  Sectors per track in storage device
              </td>
          </tr>
          <tr>
              <td align="left">
                  26-27
              </td>
              <td>
                  Number of heads in storage device
              </td>
          </tr>
          <tr>
              <td align="left">
                  28-31
              </td>
              <td>
                  Number of sectors before the start partition
              </td>
          </tr>
          <tr>
              <td align="left">
                  32-35
              </td>
              <td>
                  Number of sectors in the file system; this field will be 0 if the 2B field above
                  (bytes 19-20) is non-zero
              </td>
          </tr>
      </tbody></table>
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0090_boot_sector"></a>


    <h3>
        9. FAT Boot Sector (FAT12/16)
    </h3>
 <hr>
 <ul style="list-style-type:none;">
      <table border="1" cellpadding="5" cellspacing="0">
          <tbody><tr>
              <th>
                  Bytes
              </th>
              <th>
                  Purpose
              </th>
          </tr>
          <tr>
              <td align="left">
                  0-35
              </td>
              <td>
                  (See previous table)
              </td>
          </tr>
          <tr>
              <td align="left">
                  36
              </td>
              <td>
                  BIOS INT 13h (low level disk services) drive number
              </td>
          </tr>
          <tr>
              <td align="left">
                  37
              </td>
              <td>
                  Not used
              </td>
          </tr>
          <tr>
              <td align="left">
                  38
              </td>
              <td>
                  Extended boot signature to validate next three fields (0x29)
              </td>
          </tr>
          <tr>
              <td align="left">
                  39-42
              </td>
              <td>
                  Volume serial number
              </td>
          </tr>
          <tr>
              <td align="left">
                  43-53
              </td>
              <td>
                  Volume label, in ASCII
              </td>
          </tr>
          <tr>
              <td align="left">
                  54-61
              </td>
              <td>
                  File system type level, in ASCII. (Generally "FAT", "FAT12", or "FAT16")
              </td>
          </tr>
          <tr>
              <td align="left">
                  62-509
              </td>
              <td>
                  Not used
              </td>
          </tr>
          <tr>
              <td align="left">
                  510-511
              </td>
              <td>
                  Signature value (0xaa55)
              </td>
          </tr>
      </tbody></table>
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0100_fat12_boot_sector"></a>


    <h3>
        10. FAT12 Boot Sector
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/fat12_boot_sector.png" alt="FAT12 Boot Sector">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0110_interpretation"></a>


    <h3>
        11. Boot Sector Interpretation
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
<pre>00-02: eb 3c 90    Instructions to jump to boot code
03-0a: 4d 53 44 4f 53 35 2e 30
                   Name string (MSDOS5.0)
0b-0c: 00 02       Bytes/sector (0x0200 = 512)
0d   : 01          Sectors/cluster (1)
0e-0f: 01 00       Size of reserved area (1 sector)
10   : 02          Number of FATs (2)
11-12: e0 00       Max. number of root directory entries (0x00e0 = 224)
13-14: 40 0b       Total number of sectors (0x0b40 = 2,880)
15   : f0          Media type (removable)
16-17: 09 00       FAT size (0x0009 = 9 sectors)
18-19: 12 00       Sectors/track (0x0012 = 18)
1a-1b: 02 00       Number of heads (0x0002 = 2)
1c-1f: 00 00 00 00 Number of sector before partition (0)
20-23: 00 00 00 00 Total number of sectors (0 because 2B value not equal 0)
24   : 00          Drive number (0)
25   : 00          Unused
26   : 29          Extended boot signature
27-2a: cf cd b1 c4 Volume serial number (C4B1-CDCF)
2b-35: 4e 4f 20 4e 41 4d 45 20 20 20 20
                   Volume label ("NO NAME ")
36-3d: 46 41 54 31 32 20 20 20
                   File system type label ("FAT12 ")
3e-1fd : [snip]    Not used
1fe-1ff: 55 aa     Signature value (0xaa55)
</pre>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0120_capacity"></a>


    <h3>
        12. Capacity of this Medium
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    FAT12 allocates 12 bits per FAT entry
   </p>
   <ul>
    <li>
     <p>
      Limits addressing to 4,096 (212) clusters
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    This (removable) device is configured so that:
   </p>
   <ul>
    <li>
     <p>
      1 cluster = 1 sector
     </p>
    </li>
    <li>
     <p>
      1 sector = 512 B
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    This FAT12 table is limited in capacity to 2,097,152 bytes (2 MB)
   </p>
   <ul>
    <li>
     <p>
      I.e., 4K clusters of 512 B each
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    This device has 2,880 sectors
   </p>
   <ul>
    <li>
     <p>
      512 B clusters yields a device capacity of 1.44 MB
     </p>
    </li>
    <li>
     <p>
      Corresponds to what we would expect for a floppy
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0130_sector_assignments"></a>


    <h3>
        13. Sector Assignments
    </h3>
 <hr>
 <ul style="list-style-type:none;">
      <table border="1" cellpadding="5" cellspacing="0">
          <tbody><tr>
              <th>
                  Sector(s)
              </th>
              <th>
                  Address
              </th>
              <th>
                  Function
              </th>
          </tr>
          <tr>
              <td align="center">
                  0
              </td>
              <td align="center">
                  0x0000-0x01ff
              </td>
              <td align="center">
                  Boot Sector
              </td>
          </tr>
          <tr>
              <td align="center">
                  1-9
              </td>
              <td align="center">
                  0x0200-0x13ff
              </td>
              <td align="center">
                  File Allocation Table (primary)
              </td>
          </tr>
          <tr>
              <td align="center">
                  10-18
              </td>
              <td align="center">
                  0x1400-0x25ff
              </td>
              <td align="center">
                  File Allocation Table (secondary)
              </td>
          </tr>
          <tr>
              <td align="center">
                  19-32
              </td>
              <td align="center">
                  0x2600-0x41ff
              </td>
              <td align="center">
                  Root Directory
              </td>
          </tr>
          <tr>
              <td align="center">
                  33-2879
              </td>
              <td align="center">
                  0x4200-0x167fff
              </td>
              <td align="center">
                  File storage space
              </td>
          </tr>
      </tbody></table>
 </ul>
 <ul style="list-style-type:none;">
  <li>
   <p>
     NOTES:
   </p>
   <ul>
    <li>
     <p>
      Boot Sector is 1 sector (0x200 bytes)
     </p>
    </li>
    <li>
     <p>
      There are two FATs, each 9 sectors (0x1200 bytes)
     </p>
    </li>
    <li>
     <p>
      The Root Directory can contain 224 entries, each 32 bytes (7168, or 0x1c00, bytes; 14 sectors)
     </p>
    </li>
    <li>
     <p>
      File storage starts at sector #33 (1+9+9+14), byte #0x4200 (0x200+0x1200+0x1200+0x1c00)
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0140_root_directory"></a>


    <h3>
        14. Root Directory
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    Contains file names and metadata
   </p>
   <ul>
    <li>
     <p>
      Located immediately after FAT(s) in FAT12/16 or in a
      location specified in the FAT32 boot sector
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Supports 8.3 names or long file names
   </p>
  </li>
  <li>
   <p>
    New entries are added to the directory using a
    first-available or next-available strategy
   </p>
   <ul>
    <li>
     <p>
      First-available: Finds first unallocated entry in the
      directory (e.g., Win98)
     </p>
    </li>
    <li>
     <p>
      Next-available: Finds next available entry from the last
      allocated entry; at end of directory chain, start again at
      beginning (e.g., WinXP)
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0150_entries"></a>


    <h3>
        15. Root Directory Entries
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    The Root Directory is a series of entries describing files
   </p>
  </li>
  <li>
   <p>
    Each entry is 32 bytes and contains
   </p>
   <ul>
    <li>
     <p>
      single short (8.3) filename (SFN),
     </p>
    </li>
    <li>
     <p>
      attributes,
     </p>
    </li>
    <li>
     <p>
      MAC times,
     </p>
    </li>
    <li>
     <p>
      start cluster,
     </p>
    </li>
    <li>
     <p>
      size,
     </p>
    </li>
    <li>
     <p>
      and other metadata.
     </p>
    </li>
    <li>
     <p>
      Additional 32B entries contain the file's long filename (LFN)
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0160_sfn"></a>


    <h3>
        16. Root Directory Entry Format (SFN)
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/directory_entry_format.png" alt="Root Directory Entry Format">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0170_example"></a>


    <h3>
        17. Root Directory Example
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/root_directory_example.png" alt="Root Directory Example">
   </p>
  </li>
 </ul>
 <ul style="list-style-type:none;">
  <li>
   <p>
     Three files shown here:
   </p>
<pre>    BELIN_~1.JPG @ offset 0xff160 (belin_gayle.jpg entry starts @ offset 0xff140)
    KESSLE~1.JPG @ offset 0xff1c0 (kessler_gary.jpg entry starts @ offset 0xff1a0)
    ?HUMBS.DB @ offset 0xff200 (Thumbs.db; deleted)
</pre>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0180_sample"></a>


    <h3>
        18. Sample Root Directory Entry
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/sample_entry_01.png" alt="Sample Root Directory Entry">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0190_another_sample"></a>


    <h3>
        19. Another Sample Root Directory Entry
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/sample_entry_02.png" alt="Sample Root Directory Entry">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0200_fats_compared"></a>


    <h3>
        20. FATs Compared
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/fats_compared.png" alt="FATs Compared">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0210_fat12"></a>


    <h3>
        21. FAT12 File Allocation Table
    </h3>
 <hr>
     <table border="0" cellpadding="2" cellspacing="0">
         <tbody><tr>
             <td valign="top">
 <ul>
  <li>
   <p>
    FAT table entries are <em>packed</em> so that two cluster entries occupy three bytes with the following general format:
   </p>
<pre>    yz Zx XY
</pre>
   <p>
    where
   </p>
   <ul>
    <li>
     <p>
      xyz is the one pointer entry and
     </p>
    </li>
    <li>
     <p>
      XYZ is the second pointer entry.
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    E.g., bytes 242-244:
   </p>
<pre>    2d e0 02
</pre>
   <p>
    refer to clusters 0x02d (45) and 0x02e (46)
   </p>
  </li>
  <li>
   <p>
    Primary FAT starts at sector 1, byte 0x200 (shown here)
   </p>
  </li>
  <li>
   <p>
    The starting cluster in the directory is also a pointer into the FATs linking to the next cluster in the file
   </p>
  </li>
 </ul>
             </td>
             <td valign="top">
 <ul style="list-style-type:none;">
  <li>
   <p>
     Primary FAT sector 1:
   </p>
   <p>
    &nbsp;
    <img src="lecture-filer/fat12_sector_one.png" alt="FAT12 Primary FAT sector 1">
   </p>
  </li>
 </ul>
             </td>
         </tr>
     </tbody></table>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0220_interpreting"></a>


    <h3>
        22. Interpreting FAT12
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/interpreting_fat12.png" alt="Interpreting FAT12">
   </p>
  </li>
 </ul>
 <ul>
  <li>
   <p>
    The Primary FAT starts at Sector 1, byte #0x0200.
   </p>
  </li>
  <li>
   <p>
    Suppose a file has a starting cluster of 0x49 (73).
   </p>
   <ul>
    <li>
     <p>
      The file starts on the media at cluster #73
     </p>
    </li>
    <li>
     <p>
      The FAT entry pointing to the next cluster is in the FAT at byte #(73*1.5 + 1) = 110 (0x6e)
     </p>
    </li>
    <li>
     <p>
      Since the FAT starts at 0x0200, the FAT entry for this file is at 0x026e
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    Example:
   </p>
   <ul style="list-style-type:none;">
    <li>
     <p>
       1st cluster is 0x49 (73). FAT entry starts at high-order nibble of 0x026e (110) = 0x04a (74)
     </p>
    </li>
    <li>
     <p>
      2nd cluster is 0x4a (74). FAT entry starts at low-order nibble of 0x0270 (112) = 0x04b (75)
     </p>
    </li>
    <li>
     <p>
      3rd cluster is 0x04b (75). FAT entry starts at high-order nibble of 0x0271 (113) = 0x04c (76)
     </p>
    </li>
    <li>
     <p>
      4th cluster is 0x04c (76). FAT entry starts at low-order nibble of 0x0273 (115) = 0x04d (77)
     </p>
    </li>
    <li>
     <p>
      5th cluster is 0x04d (77). FAT entry starts at high-order nibble of 0x0274 (116) = 0xfff (end of list)
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    The physical size of this file is five clusters (2560 bytes), and occupies clusters 73, 74, 75, 76, and
    77 on the medium. (It is merely a coincidence that the clusters are contiguous.)
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0230_fat12_contents"></a>


    <h3>
        23. FAT12 Contents
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/fat12_contents.png" alt="FAT12 Contents">
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0240_formatting"></a>


    <h3>
        24. Formatting a Floppy
    </h3>
 <hr>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
    <img src="lecture-filer/formatting_floppy.png" alt="Formatting a Floppy">
   </p>
  </li>
 </ul>
 <ul>
  <li>
   <p>
    Formatting will initialize the FATs (0x00) and root directory (0xF6)
   </p>
  </li>
  <li>
   <p>
    On a floppy, format will overwrite the data area with 0xF6
   </p>
  </li>
  <li>
   <p>
    Data is NOT deleted when using Quick Format on a floppy or any format on a hard drive
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0250_formatted"></a>


    <h3>
        25. Formatted Floppy Data Structures
    </h3>
 <hr>
     <table border="0" cellpadding="2" cellspacing="0">
         <tbody><tr>
             <td valign="top">
 <ul style="list-style-type:none;">
  <li>
   <p>
     Floppy Data Structures <span style="color: blue">before</span> formatting, uninitialized:
   </p>
   <p>
    &nbsp;
    <img src="lecture-filer/formatted_floppy_before.png" alt="Floppy Data Structures before formatting">
   </p>
  </li>
 </ul>
             </td>
             <td valign="top">
 <ul style="list-style-type:none;">
  <li>
   <p>
     Floppy Data Structures <span style="color: blue">after</span> formatting,
    <be>
    initialized root directory:
   </be></p>
   <p>
    &nbsp;
    <img src="lecture-filer/formatted_floppy_after.png" alt="Floppy Data Structures after formatting">
   </p>
  </li>
 </ul>
             </td>
         </tr>
     </tbody></table>
 <ul style="list-style-type:none;">
  <li>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>
 <hr>


<a id="F01_0260_new_file"></a>


    <h3>
        26. Allocating A New File
    </h3>
 <hr>
 <ol>
  <li>
   <p>
     Find first free entry in directory and write file name
   </p>
  </li>
  <li>
   <p>
    Search FAT for unallocated cluster; set to EOF (0xFFF)
   </p>
  </li>
  <li>
   <p>
    Write that cluster's address into directory entry
   </p>
  </li>
  <li>
   <p>
    If another cluster is needed,
   </p>
   <ul>
    <li>
     <p>
      find an unallocated FAT entry,
     </p>
    </li>
    <li>
     <p>
      reset that value to EOF, and
     </p>
    </li>
    <li>
     <p>
      reset previous FAT pointer to this new cluster
     </p>
    </li>
   </ul>
   <p>
    Repeat this step as necessary
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ol>
 <hr>


<a id="F01_0270_deleting"></a>


    <h3>
        27. Deleting A File
    </h3>
 <hr>
 <ol>
  <li>
   <p>
     Find directory entry for file to delete
   </p>
  </li>
  <li>
   <p>
    Using starting cluster value in the root directory, set all FAT entries in file's cluster chain to zero
   </p>
  </li>
  <li>
   <p>
    Deallocate directory entry by overwriting first byte of the entry with 0xE5 (å)
   </p>
   <p>
    &nbsp;
   </p>
  </li>
 </ol>
 <hr>


<a id="F01_0280_information"></a>


    <h3>
        28. For More Information...
    </h3>
 <hr>
 <ul>
  <li>
   <p>
    FAT: General Overview of On-Disk Format, v1.03 (12/6/2000), Microsoft:
   </p>
   <ul style="list-style-type:none;">
    <li>
     <p>
       <tt>
      <noindex><a href="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx" target="_blank">http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx</a></noindex>
      <noindex><a href="http://digitalforensics.champlain.edu/download/FAT_general_overview-LFN.pdf" target="_blank">http://digitalforensics.champlain.edu/download/FAT_general_overview-LFN.pdf</a></noindex>
      </tt>
     </p>
    </li>
   </ul>
  </li>
  <li>
   <p>
    File Allocation Table, Wikipedia:
   </p>
   <ul style="list-style-type:none;">
    <li>
     <p>
       <tt>
      <noindex><a href="http://en.wikipedia.org/wiki/File_Allocation_Table" target="_blank">http://en.wikipedia.org/wiki/File_Allocation_Table</a></noindex>
      </tt>
     </p>
    </li>
   </ul>
   <p>
    &nbsp;
   </p>
  </li>
 </ul>


    


</body>
<!-- Mirrored from bos.asmhackers.net/docs/filesystems/fat12-16-32/docs/lecture.html by HTTrack Website Copier/3.x [XR&CO'2013], Tue, 07 Oct 2014 11:26:02 GMT -->
</html>